package com.platform.user.controller;

import com.platform.bean.PageInfo;
import com.platform.bean.Result;
import com.platform.user.entity.ItemClaimNotice;
import com.platform.user.entity.LostHelpNotice;
import com.platform.user.service.ItemAuditService;
import com.platform.user.service.ItemClaimNoticeService;
import com.platform.utils.PrintMessageUtils;
import org.json.JSONException;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.io.IOException;
import java.text.ParseException;
import java.util.Map;

@RestController
@RequestMapping("itemClaimNotice")
public class ItemClaimNoticeController {

    @Resource
    private ItemClaimNoticeService itemClaimNoticeService;
    @Resource
    private ItemAuditService itemAuditService;

    @PostMapping("redisplayItemClaimNotice")
    public Result<Map<String, Object>> redisplayItemClaimNotice(@RequestBody Map<String, Object> params) throws JSONException, IOException {
        itemClaimNoticeService.redisplayItemClaimNotice(params);
        return Result.ok("ok");
    }

    @PostMapping("illegalWithdrawalItemClaimNotice")
    public Result<Map<String, Object>> illegalWithdrawalItemClaimNotice(@RequestBody Map<String, Object> params) throws JSONException, IOException {
        itemClaimNoticeService.illegalWithdrawalItemClaimNotice(params);
        return Result.ok("ok");
    }

    @PostMapping("setItemHadReturn")
    public Result<Map<String, Object>> setItemHadReturn(@RequestBody Map<String, Object> params) throws JSONException, IOException {
        itemClaimNoticeService.setItemHadReturn(params);
        return Result.ok("ok");
    }

    @PostMapping("queryItemClaimNoticeByPage")
    public Result<Map<String, Object>> queryItemClaimNoticeByPage(@RequestBody Map<String, Object> params) {
        PageInfo<ItemClaimNotice> itemClaimNoticePageInfo = itemClaimNoticeService.queryItemClaimNoticeByPage(params);
        return Result.ok(itemClaimNoticePageInfo);
    }

    @PostMapping("queryOneItemClaimNoticeByItemId")
    public Result<Map<String, Object>> queryOneItemClaimNoticeByItemId(@RequestBody Map<String, Object> params) {
        ItemClaimNotice itemClaimNotice = itemClaimNoticeService.queryOneItemClaimNoticeByItemId(params);
        return Result.ok(itemClaimNotice);
    }

    @PostMapping("addItemClaimNotice")
    public Result<Map<String, Object>> addItemClaimNotice(@RequestBody Map<String, Object> params) throws ParseException {
        ItemClaimNotice itemClaimNotice = itemClaimNoticeService.addItemClaimNotice(params);
        Integer id = itemClaimNotice.getId();
        if (id != null) {
            params.put("itemId", id);
            params.put("itemSort", 1);
            params.put("itemName", itemClaimNotice.getItemName());
            itemAuditService.addItemAudit(params);
        }
        return Result.ok("申请成功");
    }
}
